package mobidever.mygodutch.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import mobidever.mygodutch.R;
import mobidever.mygodutch.adapter.base.AdapterBase;
import mobidever.mygodutch.bussiness.BussinessAccountBook;
import mobidever.mygodutch.controls.SliderItem;
import mobidever.mygodutch.model.ModelAccountBook;

public class AdapterAccountBook extends AdapterBase
{
	BussinessAccountBook mBussinessAccountBook;

	private class Holder
	{
		ImageView ivIcon;
		TextView tvName;
		TextView tvToatl;
		TextView tvMoney;
	}

	public AdapterAccountBook(List pList, Context pContext)
	{
		super(pList, pContext);
		mBussinessAccountBook = new BussinessAccountBook(pContext);
		List<ModelAccountBook> _List = mBussinessAccountBook.getAccountBooks("");
		setList(_List);
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{
		
		List<ModelAccountBook> _List = getList();
		
		Holder _Holder;
		if (convertView == null)
		{
			convertView = getLayoutInflater().inflate(R.layout.account_book_list_item,
					null);

			_Holder = new Holder();

			_Holder.ivIcon = (ImageView) convertView.findViewById(R.id.ivAccountBookIcon);
			
			_Holder.tvName = (TextView) convertView.findViewById(R.id.tvAccountBookName);
			_Holder.tvToatl = (TextView) convertView.findViewById(R.id.tvTotal);
			_Holder.tvMoney = (TextView) convertView.findViewById(R.id.tvMoney);
			convertView.setTag(_Holder);
		} else
		{
			_Holder = (Holder) convertView.getTag();
		}
		
		ModelAccountBook _AccountBook = (ModelAccountBook) getList().get(position);
		
		if(_AccountBook.getIsDefault() == 1)
		{
			_Holder.ivIcon.setImageResource(R.drawable.account_book_default);
		}else {
			_Holder.ivIcon.setImageResource(R.drawable.account_book_big_icon);
		}
		_Holder.tvName.setText(_List.get(position).getAccountBookName());
		return convertView;
	}

}
